package club.twelveblog.tblog.controller;

import club.twelveblog.tblog.common.enums.ExceptionEnum;
import club.twelveblog.tblog.common.exception.BlogException;
import club.twelveblog.tblog.common.vo.BlogInfoVo;
import club.twelveblog.tblog.entity.Category;
import club.twelveblog.tblog.service.BlogInfoService;
import club.twelveblog.tblog.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/tblog/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    @Autowired
    private BlogInfoService blogInfoService;
    /**
     * 查找所有分类
     * @return
     */
    @GetMapping
    public ResponseEntity<List<Category>> findAllCategory(){
        List<Category> categoryList = categoryService.findAllCategory();
        if(categoryList.size()==0){
            throw new BlogException(ExceptionEnum.CATEGORY_NOT_FOUND);
        }
        return ResponseEntity.status(HttpStatus.OK).body(categoryList);
    }

    /**
     * 根据分类名称查找对应博客文章
     * @param category
     * @return
     */
//    @GetMapping("/{category}")
//    public ResponseEntity<List<BlogInfoVo>> findBlogByCategory(@PathVariable(value = "category") String category,
//                                                               @RequestParam(value = "page",defaultValue = "1") int page
//        ) {
//        try {
//            List<BlogInfoVo>infoVos = blogInfoService.findBlogByCategory(category, page);
//            return null;
//            //return ResponseEntity.ok(infoVos);
//        } catch (BlogException e) {
//            throw new BlogException(ExceptionEnum.CATEGORY_NOT_FOUND);
//        }
//
//    }

}
